package com.ces.knacky.controller.tools;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ces.knacky.framework.controller.BaseController;
import com.ces.knacky.framework.model.IEntity;
import com.ces.knacky.model.Flag;
import com.ces.knacky.model.Inventory;
import com.ces.knacky.model.Item;
import com.ces.knacky.model.UserTable;
@Controller
public class SaveInventoryController extends BaseController {
	
	
	private String code;
	private String itemid;
	
	@RequestMapping ("/saveInventory.htm")	
	public String execute(){
		System.out.println("Inside Save Role");
		Inventory inventory = new Inventory();
		inventory.setCode(code);
		inventory.setCreateTime(new Date());
		inventory.setUpdateTime(new Date());
		IEntity entity = commonService.findFirstByDescription(UserTable.class, "admin");
		inventory.setUser((UserTable)entity);
		entity = commonService.findFirstByDescription(Flag.class, "ACTIVE");
		inventory.setFlag((Flag)entity);
		//entity = commonService.findFirstByDescription(Item.class, "item");
		entity = commonService.findFirstByDescription(Item.class, itemid);
		//entity = commonService.load(Item.class, itemid);
		inventory.setItem((Item)entity);
		commonService.add(inventory);
		return "saveInventory";
		
		
	}

	/**
	 * @return the code
	 */	
	public String getCode() {
		return code;
	}

	/**
	 * @param code the code to set
	 */
	@ModelAttribute("code")
	public void setCode(String code) {
		this.code = code;
	}
	
	/**
	 * @return the itemid
	 */	
	public String getItemId() {
		return itemid;
	}

	/**
	 * @param itemid the itemid to set
	 */
	@ModelAttribute("itemid")
	public void setItemId(String itemid) {
		this.itemid = itemid;
	}

}
